/**
 * 登录
 */
let versionStatic= 2025063001;

define(function () {
    $.module("SYS.login", function () {
        return {
            init: function () {
                this.loadData();
            },
            loadData: function () {
                var is_login = $.cookie("is_login");  //判断是否登录
                if (is_login == "true") {
                    location.href = "index.html?v=" + versionStatic;
                }
            },
            login: function () {
                var phone = $("#phone").val();
                var pwd = $("#password").val();

                // 跨域调用API接口
                $.ajax({
                    url: '/user/login',
                    common: {},
                    data: {
                        parameters: JSON.stringify({
                            common: {},
                            data: {phone: phone, password: pwd}
                        })
                    },
                    success: function (data) {
                        // console.log(data)
                        if (data.code == 1) {
                            $.cookie("is_login", "true", {path: "/", expires: 24 * 60 * 60 * 1000});
                            $.cookie('u_id', data.data.uid, {path: "/", expires: 24 * 60 * 60 * 1000});
                            $.cookie('u_name', data.data.cn_name, {path: "/", expires: 24 * 60 * 60 * 1000});
                            // $.cookie('sid', data.data.code||0, {path: "/", expires: 24 * 60 * 60 * 1000});
                            $.cookie('sid', 0, {path: "/", expires: 24 * 60 * 60 * 1000});
                            $.cookie('token', data.data.token, {path: "/", expires: 24 * 60 * 60 * 1000});
                            $.cookie('platform_user_id', data.data.platform_user_id, {path: "/", expires: 24 * 60 * 60 * 1000});

                            location.href = "index.html?v=" + versionStatic;
                        } else {
                            $(".my_message").html(data.msg);
                        }
                    },
                    error: function () {
                        $(".my_message").html("登录失败！");
                    }
                });
                return false;
            }
        }
    });

    SYS.login.init();
});